using Headsight.BPMN2WF.BPMN.Schemas;
using Headsight.BPMN2WF.Testing.TestObjCtors;
using Headsight.BPMN2WF.Transformation.Transformers;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Headsight.BPMN2WF.Transformation.BPMN2TransformerMappings
{
    [TestClass]
    public class BPMN2WFTransformationsTest
    {
        private BPMN2WFTransformations _sut;

        [TestInitialize]
        public void SetUp()
        {
            _sut = new BPMN2WFTransformations();
        }

        [TestMethod]
        public void Register_Get()
        {
            _sut.Register(typeof (tUserTask), typeof (BPMN2WFTransformationWriteLine));
            _sut.Register(typeof (tScriptTask), typeof (BPMN2WFTransformationTerminateEndEvent));

            var actual1 = _sut.Get(new BPMNFlowNodeCtor().WithTFlowElement(new tUserTask()).Create());
            var actual2 = _sut.Get(new BPMNFlowNodeCtor().WithTFlowElement(new tScriptTask()).Create());

            Assert.IsInstanceOfType(actual1, typeof(BPMN2WFTransformationWriteLine));
            Assert.IsInstanceOfType(actual2, typeof(BPMN2WFTransformationTerminateEndEvent));
        }

        [TestMethod]
        public void Register_Get_always_returns_new_instance()
        {
            _sut.Register(typeof (tUserTask), typeof (BPMN2WFTransformationWriteLine));

            var actual1 = _sut.Get(new BPMNFlowNodeCtor().WithTFlowElement(new tUserTask()).Create());
            var actual2 = _sut.Get(new BPMNFlowNodeCtor().WithTFlowElement(new tUserTask()).Create());

            Assert.IsNotNull(actual1);
            Assert.IsNotNull(actual2);

            Assert.AreNotSame(actual1, actual2);
        }

        [TestMethod]
        public void Default_Get()
        {
            _sut.Default = typeof (BPMN2WFTransformationWriteLine);
            _sut.Register(typeof (tUserTask), typeof(BPMN2WFTransformationTerminateEndEvent));

            var actual1 = _sut.Get(new BPMNFlowNodeCtor().WithTFlowElement(new tUserTask()).Create());
            var actual2 = _sut.Get(new BPMNFlowNodeCtor().WithTFlowElement(new tScriptTask()).Create());
            var actual3 = _sut.Get(new BPMNFlowNodeCtor().WithTFlowElement(new tReceiveTask()).Create());

            Assert.IsInstanceOfType(actual1, typeof(BPMN2WFTransformationTerminateEndEvent));
            Assert.IsInstanceOfType(actual2, typeof(BPMN2WFTransformationWriteLine));
            Assert.IsInstanceOfType(actual3, typeof(BPMN2WFTransformationWriteLine));
        }
    }
}